package com.jiangds.open.util;

/**
 * {@link NumberUtil}  数值类型工具
 *
 * @author jiangliang
 * @since 2021/1/7 13:45
 */
public class NumberUtil {


    public static boolean isInteger(Class<?> type){
        return type == Integer.class || type == Short.class || type == Byte.class
                || type == int.class || type == short.class || type == byte.class;
    }

    public static boolean isLong(Class<?> type){
        return type == Long.class || type == long.class;
    }

    public static boolean isDouble(Class<?> type){
        return type == Double.class || type == Float.class || type == double.class || type == float.class;
    }

    public static Integer toIntegerClass(Object target){
        if(target == null){
            return null;
        }
        Class<?> type = target.getClass();
        if( type == Byte.class){
            return ((Byte) target).intValue();
        }else if( type == Short.class){
            return ((Short) target).intValue();
        }
        return (Integer)target;
    }

    public static Double toDoubleClass(Object target){
        if(target == null){
            return null;
        }
        Class<?> type = target.getClass();
        if( type == Float.class){
            return ((Float) target).doubleValue();
        }
        return (Double)target;
    }

    public static Long toLongClass(Object target){
        if(target == null){
            return null;
        }
        return (Long) target;
    }
}
